<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <button class="btn">通知执行</button>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script>
      const $eventBus = $.Callbacks();

      // 不同模块之间都需要在某个操作下(被点击时)执行什么事情(方法)
      const btn = document.querySelector('.btn');
      btn.addEventListener('click', () => {
        $eventBus.fire(10, 300);
      });
      (function () {
        // a模块
        let fn1 = (x, y) => console.log('fn1', x, y);
        $eventBus.add(fn1);
      })();
      // b模块
      (function () {
        let fn2 = () => console.log('fn2');
        $eventBus.add(fn2);
      })();
      // c模块
      (function () {
        let fn3 = () => console.log('fn3');
        $eventBus.add(fn3);
      })();

      // console.log($eventBus);
    </script>
  </body>
</html>
